package cn.tedu.ems.studyfile.controller;

import cn.tedu.ems.studyfile.pojo.dto.*;
import cn.tedu.ems.studyfile.pojo.vo.StudyFileVO;
import cn.tedu.ems.studyfile.service.ApplicationService;
import cn.tedu.ems.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/study")
@Api(tags = "文件分类")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @ApiOperation("查询所有分类")
    @GetMapping("categoryList")
    public JsonResult selectfile(){
       List<CategoryListDTO> list= applicationService.selectfile();
       return JsonResult.ok(list);
    }

    @ApiOperation("详情")
    @GetMapping("details/{id}")
    public JsonResult details(@PathVariable Integer id) {
        return JsonResult.ok(applicationService.selectById(id));
    }


    @ApiOperation("搜索框搜索")
    @GetMapping("select")
    public JsonResult selectLists(SearchFor searchFor){
        log.debug("搜索框搜索入参searchFor:{}",searchFor);
        List<StudyFileVO> list= applicationService.selectListsTitleStateArticleVideoCategoryId(searchFor);
        log.debug("搜索框搜索出参list:{}",list);
        return JsonResult.ok(list);

    }

    @ApiOperation("发布文章")
    @PostMapping("insert")
    public JsonResult insertRelease(@RequestBody StudyReleaseDTO studyReleaseDTO){
        log.debug("发布文章入参studyRelease:{}",studyReleaseDTO);
        boolean b=applicationService.insertRelease(studyReleaseDTO);
        return JsonResult.ok(b);
    }

    @ApiOperation("修改状态")
    @PostMapping("update")
    public JsonResult updateState(StateDTO stateDTO){
        log.debug("修改状态入参stateDTO:{}",stateDTO);
        boolean b=applicationService.updateState(stateDTO);
        return JsonResult.ok(b);
    }

    @ApiOperation("编辑文章")
    @PostMapping("updateArticle")
    public JsonResult updateArticle(@RequestBody StudyUpdateArticle studyUpdateArticle){
        log.debug("修改文章入参studyReleaseDTO:{}",studyUpdateArticle);
        boolean b =applicationService.updateArticle(studyUpdateArticle);
        return JsonResult.ok(b);
    }

    @ApiOperation("删除文章")  //软删除
    @PostMapping("delete")
    public JsonResult deleteArticle(StudyDeleteDTO studyDeleteDTO){
        log.debug("删除文章入参studyDeleteDTO:{}",studyDeleteDTO);
        boolean b =applicationService.deleteArticle(studyDeleteDTO);
        return JsonResult.ok(b);
    }
}
